package lp.xian.materials.service.impl;

import java.util.Date;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import lp.xian.materials.domain.Warehouse;
import lp.xian.materials.domain.WarehouseWarrant;
import lp.xian.materials.mapper.WarehouseWarrantMapper;
import lp.xian.materials.vo.MaterialsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import lp.xian.materials.mapper.MaterialsMapper;
import lp.xian.materials.domain.Materials;
import lp.xian.materials.service.IMaterialsService;

/**
 * 原料表Service业务层处理
 *
 * @author zh
 * @date 2023-07-01
 */
@Service
public class MaterialsServiceImpl implements IMaterialsService
{
    @Autowired
    private MaterialsMapper materialsMapper;
    @Autowired
    private WarehouseWarrantMapper warehouseWarrantMapper;

    /**
     * 查询原料表
     *
     * @param lpMaterialsId 原料表主键
     * @return 原料表
     */
    @Override
    public Materials selectMaterialsByLpMaterialsId(Integer lpMaterialsId)
    {
        return materialsMapper.selectMaterialsByLpMaterialsId(lpMaterialsId);
    }

    /**
     * 查询原料表列表
     *
     * @param materials 原料表
     * @return 原料表
     */
    @Override
    public List<Materials> selectMaterialsList(Materials materials)
    {
        return materialsMapper.selectMaterialsList(materials);
    }

    /**
     * 新增原料表
     *
     * @param materials 原料表
     * @return 结果
     */
    @Override
    public int insertMaterials(Materials materials)
    {
        materials.setCreateTime(DateUtils.getNowDate());
        return materialsMapper.insertMaterials(materials);
    }

    /**
     * 修改原料表
     *
     * @param materials 原料表
     * @return 结果
     */
    @Override
    public int updateMaterials(Materials materials)
    {
        materials.setUpdateTime(DateUtils.getNowDate());
        return materialsMapper.updateMaterials(materials);
    }

    /**
     * 批量删除原料表
     *
     * @param lpMaterialsIds 需要删除的原料表主键
     * @return 结果
     */
    @Override
    public int deleteMaterialsByLpMaterialsIds(Integer[] lpMaterialsIds)
    {
        return materialsMapper.deleteMaterialsByLpMaterialsIds(lpMaterialsIds);
    }

    /**
     * 删除原料表信息
     *
     * @param lpMaterialsId 原料表主键
     * @return 结果
     */
    @Override
    public int deleteMaterialsByLpMaterialsId(Integer lpMaterialsId)
    {
        return materialsMapper.deleteMaterialsByLpMaterialsId(lpMaterialsId);
    }

    @Override
    public int warehouseMaterials(MaterialsVo materialsvo) {
        WarehouseWarrant warehouseWarrant=new WarehouseWarrant();
        warehouseWarrant.setWarehouseWarrantName(materialsvo.getMaterialsName());//名称
        warehouseWarrant.setWarehouseWarrantPrice(materialsvo.getMaterialsPrice());//价格
        warehouseWarrant.setWarehouseWarrantNum(materialsvo.getMaterialsNum());//数量
        warehouseWarrant.setUnit(materialsvo.getUnit());//单位
        warehouseWarrant.setAuditStatus(0);//未审核
        warehouseWarrant.setCreateTime(new Date());//创建时间
        warehouseWarrant.setCreateBy(SecurityUtils.getUsername());
        return warehouseWarrantMapper.insertWarehouseWarrant(warehouseWarrant);
    }
}
